/*
 * @Author: 邱狮杰
 * @Date: 2021-09-05 12:49:13
 * @LastEditTime : 2021-09-09 09:59:00
 * @FilePath     : /newhope/src/utils/toImage.ts
 * @Description: 描述
 */
import html2canvas from "html2canvas";
// 生成快照
export const convertToImage = async (container: HTMLElement, options = {}) => {
  // 设置放大倍数
  const scale = 1;
  // window.pageYoffset = 0;

  document.documentElement.scrollTop = 0;

  document.body.scrollTop = 0;
  // 传入节点原始宽高
  const width = container.offsetWidth;
  const height = container.offsetHeight;

  // html2canvas配置项
  const ops = {
    scale,
    width,
    height,
    dpi: 350,
    useCORS: true,
    allowTaint: false,
    ...options,
  };
  const canvas = await html2canvas(container, ops);
  return canvas.toDataURL();
};
